package com.zt.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.zt.domain.User;
import com.zt.mapper.UserMapper;
import com.zt.utils.TokenUtils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 用户接口1
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户管理接口")
public class UserController extends BaseController {
    
    @Autowired
    private UserMapper userMapper;
    
    /**
     * 获取当前登录用户信息
     */
    @GetMapping("/user/info")
    @ApiOperation("获取当前登录用户信息")
    public AjaxResult getUserInfo(@RequestHeader("Authorization") String token) {
        try {
            // 解析token
            Long userId = TokenUtils.getUserIdFromToken(token.replace("Bearer ", ""));
            
            // 查询用户信息
            User user = userMapper.selectUserById(userId);
            if (user != null) {
                // 隐藏敏感信息
                user.setOpenid(null);
                user.setUnionid(null);
                return AjaxResult.success(user);
            } else {
                return AjaxResult.error("用户不存在");
            }
        } catch (Exception e) {
            return AjaxResult.error("获取用户信息失败");
        }
    }
} 